package com.neusoft.weixin.web.drug;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.weixin.service.DrugService;

@Controller
@RequestMapping("/web/drug")
public class DrugController {
	
	@Autowired
	protected DrugService drugService;
	
	private Logger log = LoggerFactory.getLogger(DrugController.class);
	
	@RequestMapping(params = "method=queryDrug") 
	@ResponseBody
	public String queryDrug(HttpServletRequest request, HttpServletResponse response){
		PrintWriter out = null;
		try {
			out = response.getWriter();
			//前台 返回的参数（参数名称不用改）
			String code = request.getParameter("code");
			String captcha = request.getParameter("captcha");

			log.info("code:" + code);
			log.info("captcha:" + captcha);
			
			out.write(drugService.getHtml(code, captcha));
		} catch (Exception e)
		{
			log.error(e.getMessage());
		} finally {
			if(out!=null){
				out.flush();
				out.close();
			}
		}
		return null;
		
	}
	
	@RequestMapping(value = "/queryDrug")
	public String query(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		//前台 返回的参数（参数名称不用改）
		String code = request.getParameter("code");
		String captcha = request.getParameter("captcha");

		log.info(request.getParameterMap().toString());
		log.info("code:" + code);
		log.info("captcha:" + captcha);
		
		request.getSession().setAttribute("html", drugService.getHtml(code, captcha));
		
		return "web/drug/view";
		
	}
	
}
